package cn.ava.order.controller;

import cn.ava.basic.utils.AjaxResult;
import cn.ava.basic.utils.PageList;
import cn.ava.order.domain.OrderPetAcquisition;
import cn.ava.order.dot.confirmOrderDto;
import cn.ava.order.query.OrderPetAcquisitionQuery;
import cn.ava.order.service.IOrderPetAcquisitionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @ClassName: OrderPetAcquisitionController
 * @Description: 宠物收购订单管理
 * @Author: Avavaava
 * @Date: 2022/7/26 16:25
 * @version: 23.53
 *
 */
@RestController
@RequestMapping("/orderPetAcquisition")
public class OrderPetAcquisitionController {
    @Autowired
    public IOrderPetAcquisitionService orderPetAcquisitionService;


    /**
     * 保存和修改公用的
     * @param orderPetAcquisition  传递的实体
     * @return Ajaxresult转换结果
     */
    @PutMapping
    public AjaxResult addOrUpdate(@RequestBody OrderPetAcquisition orderPetAcquisition){
        try {
            if( orderPetAcquisition.getId()!=null)
                orderPetAcquisitionService.update(orderPetAcquisition);
            else
                orderPetAcquisitionService.add(orderPetAcquisition);
            return new AjaxResult();
        } catch (Exception e) {
            e.printStackTrace(); 
            return new AjaxResult().setMessage("服务器崩溃！").setSuccess(false);
        }
    }
    /**
    * 删除对象信息
    * @param id
    * @return
    */
    @DeleteMapping(value="/{id}")
    public AjaxResult delete(@PathVariable("id") Long id){
        try {
            orderPetAcquisitionService.delete(id);
            return new AjaxResult();
        } catch (Exception e) {
        e.printStackTrace();
            return new AjaxResult().setMessage("服务器崩溃！").setSuccess(false);
        }
    }
	
    //获取用户
    @GetMapping("/{id}")
    public OrderPetAcquisition getById(@PathVariable("id")Long id)
    {
        return orderPetAcquisitionService.getById(id);
    }


    /**
    * 查看所有的员工信息
    * @return
    */
    @GetMapping()
    public List<OrderPetAcquisition> list(){

        return orderPetAcquisitionService.loadAll();
    }


    /**
    * 分页查询数据
    *
    * @param query 查询对象
    * @return PageList 分页对象
    */
    @PostMapping()
    public PageList<OrderPetAcquisition> json(@RequestBody OrderPetAcquisitionQuery query)
    {
        return orderPetAcquisitionService.queryData(query);
    }


    /**
     * @Title: confirmOrder
     * @Description: 订单确认
     * @Author: Avavaava
     * @Version: 23.53
     * @Date: 2022/7/26 16:25
     * @param:
     * @return:
     */
    @PostMapping("/confirm")
    public AjaxResult confirmOrder(@RequestBody confirmOrderDto confirmOrderDto){
        try {
            orderPetAcquisitionService.confirmOrder(confirmOrderDto);
            return new AjaxResult();
        } catch (Exception e) {
            e.printStackTrace();
            return new AjaxResult().setMessage("服务器崩溃！").setSuccess(false);
        }
    }


    /**
     * @Title: cancelOrder
     * @Description: 订单取消
     * @Author: Avavaava
     * @Version: 23.53
     * @Date: 2022/7/26 16:25
     * @param:
     * @return:
     */
    @PostMapping("/cancelOrder/{id}")
    public AjaxResult cancelOrder(@PathVariable("id") Long id){
        try {
            orderPetAcquisitionService.cancelOrder(id);
            return new AjaxResult();
        } catch (Exception e) {
            e.printStackTrace();
            return new AjaxResult().setMessage("服务器崩溃！").setSuccess(false);
        }
    }



}
